//
// Created on 2024/9/10.
//
// Node APIs are not fully supported. To solve the compilation error of the interface cannot be found,
// please include "napi/native_api.h".

#pragma once
#include "api/jsep.h"
#include "rtc_client/rtc_wrapper.h"

// use for sdp function observer 
namespace ohosrtc {

class PeerConnectionChannel;

using CreateSDPObserver = webrtc::CreateSessionDescriptionObserver;
using SetSDPObserver = webrtc::SetSessionDescriptionObserver;
using SetLocalDescriptionObserver = webrtc::SetLocalDescriptionObserverInterface;
using SetRemoteDescriptionObserver = webrtc::SetRemoteDescriptionObserverInterface;

class FunctionalCreateSdpObserver : public CreateSDPObserver {
  public:
  static rtc::scoped_refptr<FunctionalCreateSdpObserver>
  Create(std::function<void(SDP *)> on_success,
         std::function<void(const std::string &)> on_failure);

  void OnSuccess(SDP *desc) override;
  void OnFailure(RTCError error) override;

  protected:
  FunctionalCreateSdpObserver(std::function<void(SDP *)> on_success,
                              std::function<void(const std::string &)> on_failure);

  private:
  std::function<void(SDP *)> on_success_;
  std::function<void(const std::string &)> on_failure_;
};


class FunctionalSetSdpObserver : public SetSDPObserver {


  public:
  static rtc::scoped_refptr<FunctionalSetSdpObserver> Create(std::function<void()> on_success,
                                          std::function<void(const std::string &)> on_failure);
  void OnSuccess() override;
  void OnFailure(RTCError error) override;

  protected:
  FunctionalSetSdpObserver(std::function<void()> on_success, std::function<void(const std::string &error)> on_failure);

  private:
  std::function<void()> on_success_;
  std::function<void(const std::string &error)> on_failure_;
};

class FunctionalSetLocalDescriptionObserver : public SetLocalDescriptionObserver {
  
  public:
  static rtc::scoped_refptr<FunctionalSetLocalDescriptionObserver> Create(std::function<void(const webrtc::RTCError)> on_completion);
  
  void OnSetLocalDescriptionComplete(webrtc::RTCError error) override;
  
  protected:
  FunctionalSetLocalDescriptionObserver(std::function<void(const webrtc::RTCError)> on_completion);
  private:
  std::function<void(const webrtc::RTCError error)> on_completion_;
};

class FunctionalSetRemoteDescriptionObserver : public SetRemoteDescriptionObserver {
  
  public:
  static rtc::scoped_refptr<FunctionalSetRemoteDescriptionObserver> Create(std::function<void(const webrtc::RTCError)> on_completion);
  
  void OnSetRemoteDescriptionComplete(webrtc::RTCError error) override;
  
  protected:
  FunctionalSetRemoteDescriptionObserver(std::function<void(const webrtc::RTCError)> on_completion);
  private:
  std::function<void(const webrtc::RTCError error)> on_completion_;
};

} // namespace ohosrtc
